let {Service} = require('egg');

class ListService extends Service{
    //添加
    async add(phone,nick_name,tags,role,id_card,address,info,create_time,end_type){
        await this.app.mysql.query('insert into list (phone,nick_name,tags,role,id_card,address,info,create_time,end_type) values (?,?,?,?,?,?,?,?,?)',[phone,nick_name,tags,role,id_card,address,info,create_time,end_type])
    }
    //编辑
    async edit(phone,nick_name,tags,role,id_card,address,info,create_time,id){
        await this.app.mysql.query('update list set phone=?,nick_name=?,tags=?,role=?,id_card=?,address=?,info=?,create_time=? where id=?',[phone,nick_name,tags,role,id_card,address,info,create_time,id])
    }
    //删除
    async del(ids){
        //ids  数组  [3,4]
        let arr = ids.split(',');
        for(let i = 0;i<arr.length;i++){
            await this.app.mysql.query('delete from list where id=?',[arr[i]])
        }
    }
    //查询
    async list(){
        return this.app.mysql.query('select * from list');
    }
}

module.exports = ListService